
package com.ruoyi.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TProject;
import com.ruoyi.system.service.ITProjectService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TConsumeRecords;
import com.ruoyi.system.service.ITConsumeRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消耗记录Controller
 * 
 * @author ruoyi
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/system/consumeRecords")
public class TConsumeRecordsController extends BaseController
{
    @Autowired
    private ITConsumeRecordsService tConsumeRecordsService;

    /**
     * 管理专用
     */
    @PostMapping("/allSummary")
    public AjaxResult allSummary(@RequestBody TConsumeRecords tConsumeRecords){
        return AjaxResult.success(tConsumeRecordsService.allSummary(tConsumeRecords));
    }

    /**
     * 投手专用
     */
    @PostMapping("/mySummary")
    public AjaxResult mySummary(@RequestBody TConsumeRecords tConsumeRecords){
        tConsumeRecords.setUid(getUserId());
        return AjaxResult.success(tConsumeRecordsService.mySummary(tConsumeRecords));
    }
    /**
     * 查询消耗记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:consumeRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(TConsumeRecords tConsumeRecords)
    {
        startPage();
        tConsumeRecords.setUid(getUserId());
        List<TConsumeRecords> list = tConsumeRecordsService.selectTConsumeRecordsList(tConsumeRecords);
        return getDataTable(list);
    }

    /**
     * 查询消耗记录列表(管理)
     */
//    @PreAuthorize("@ss.hasPermi('system:consumeData:list')")
    @GetMapping("/adminList")
    public TableDataInfo adminList(TConsumeRecords tConsumeRecords)
    {
        startPage();
        List<TConsumeRecords> list = tConsumeRecordsService.selectTConsumeRecordsList(tConsumeRecords);
        return getDataTable(list);
    }

    /**
     * 导出消耗记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:consumeRecords:export')")
    @Log(title = "消耗记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TConsumeRecords tConsumeRecords)
    {
        List<TConsumeRecords> list = tConsumeRecordsService.selectTConsumeRecordsList(tConsumeRecords);
        ExcelUtil<TConsumeRecords> util = new ExcelUtil<TConsumeRecords>(TConsumeRecords.class);
        util.exportExcel(response, list, "消耗记录数据");
    }

    /**
     * 获取消耗记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:consumeRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tConsumeRecordsService.selectTConsumeRecordsById(id));
    }

    /**
     * 新增消耗记录
     */
    @PreAuthorize("@ss.hasPermi('system:consumeRecords:add')")
    @Log(title = "消耗记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TConsumeRecords tConsumeRecords)
    {
        tConsumeRecords.setUid(getUserId());
        return toAjax(tConsumeRecordsService.insertTConsumeRecords(tConsumeRecords));
    }

    /**
     * 修改消耗记录
     */
    @PreAuthorize("@ss.hasPermi('system:consumeRecords:edit')")
    @Log(title = "消耗记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TConsumeRecords tConsumeRecords)
    {
        return toAjax(tConsumeRecordsService.updateTConsumeRecords(tConsumeRecords));
    }

    /**
     * 删除消耗记录
     */
    @PreAuthorize("@ss.hasPermi('system:consumeRecords:remove')")
    @Log(title = "消耗记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tConsumeRecordsService.deleteTConsumeRecordsByIds(ids));
    }

    @Autowired
    private ITProjectService tProjectService;
    /**
     * 项目列表
     */
    @GetMapping("/getProList")
    public AjaxResult getProList(){
        TProject tProject = new TProject();
        List<TProject> list = tProjectService.selectTProjectList(tProject);
        return AjaxResult.success(list);
    }
}
